<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>销毁管理</title>
</head>
<body>
	<script type="text/javascript">

		$(function() {

			//销毁记录表
			$('#destruction-dg').datagrid({
				url : 'find-destroyjl',
				pagination : true,
				pageNumber : 1,
				pageSize : 6,
				singleSelect: true,
				pageList : [6, 12 ],
				columns : [ [
					{field : 'destroy_id',				title : '销毁单号',		width : 170},
					{field : 'destroy_head',			title : '负责人',		width : 170},
					{field : 'destroy_allquantity',		title : '总数量',		width : 170},
					{field : 'destroy_time',			title : '销毁时间',		width : 170,formatter:comFormatDate},
					{field : 'destroy_reason',			title : '销毁原因',		width : 195},
					{field : 'destroy_checkpeople',		title : '审核人',		width : 170}
				] ],
				onDblClickRow : function(rowIndex, rowData) {
					$("#destructionjl-win").window("open");
					//给销毁单号赋值
				    $("#destruction-xhdh").textbox('setValue',rowData.destroy_id);
				  	//给销毁时间赋值
				  	var s=rowData.destroy_time;
					var t=CurentTime(s);
				    $("#destruction-xhsj").textbox('setValue',t);
				  	//给销毁原因赋值
				    $("#destruction-yy").textbox('setValue',rowData.destroy_reason);
				  	
				  	//获取销毁单号
				  	var destroyid = $("#destruction-xhdh").textbox("getValue");
				  	
				  	//根据销毁单号获取
					$.ajax({  
                        url: 'find-destroydetails',  
                        data:{'destroyid' :destroyid},
                        type: 'POST',  
                        dataType:"json",
					 	success: function (data) {  
					 				//遍历数据前清空datagrid数据
					 				$('#destructionjl-dg').datagrid('loadData',{total:0,rows:[]});
					 				console.log(data.result);
					 				//循环销毁商品数据
					                for ( var machine in data.result) {
					                    var row_data = {
					    					'inventory_number' : data.result[machine].inventory_number,
					                        'drug_name' : data.result[machine].drug_name,
					                        'drug_standard' : data.result[machine].drug_standard,
					                        'drug_purchase_price' : data.result[machine].drug_purchase_price,
					                        'destroy_details_quantity' : data.result[machine].destroy_details_quantity,
					                        'destroy_details_jine' : data.result[machine].drug_purchase_price*data.result[machine].destroy_details_quantity,
					                        'destroy_pici' : data.result[machine].destroy_pici				                        
					                    };
					                    $('#destructionjl-dg').datagrid('appendRow', row_data);
					                }
						     }, 				     
	                        Error: function () {  
	                            alert(Error);  
	                        }                   
	                    });    
					}
			});
			
			//销毁表
			$('#destructiontb-dg').datagrid({
				url : 'find-destroy',
				pagination : true,
				pageNumber : 1,
				pageSize : 3,
				singleSelect: true,
				pageList : [ 3, 6 ],
				columns : [ [
					{field : 'destroy_id',				title : '销毁单号',		width : 210},
					{field : 'destroy_head',			title : '负责人',		width : 210},
					{field : 'destroy_allquantity',		title : '总数量',		width : 210},
					{field : 'destroy_time',			title : '销毁时间',		width : 205,formatter:comFormatDate},
					{field : 'destroy_reason',			title : '销毁原因',		width : 210}
				] ],
				onDblClickRow : function(rowIndex, rowData) {
					$("#destructiontbxq-win").window("open");
					//给销毁单号赋值
				    $("#destruction-xhdh1").textbox('setValue',rowData.destroy_id);
				  	//给销毁时间赋值
				  	var s=rowData.destroy_time;
					var t=CurentTime(s);
				    $("#destruction-xhsj1").textbox('setValue',t);
				  	//给销毁原因赋值
				    $("#destruction-yy1").textbox('setValue',rowData.destroy_reason);
				  	
				  	//获取销毁单号
				  	var destroyid = $("#destruction-xhdh1").textbox("getValue");
				  	
				  	//根据销毁单号获取
					$.ajax({  
                        url: 'find-destroydetails',  
                        data:{'destroyid' :destroyid},
                        type: 'POST',  
                        dataType:"json",
					 	success: function (data) {  
					 				//遍历数据前清空datagrid数据
					 				$('#destructionxq-dg').datagrid('loadData',{total:0,rows:[]});
					 				console.log(data.result);
					 				//循环销毁商品数据
					                for ( var machine in data.result) {
					                    var row_data = {
					    					'inventory_number' : data.result[machine].inventory_number,
					                        'drug_name' : data.result[machine].drug_name,
					                        'drug_standard' : data.result[machine].drug_standard,
					                        'drug_purchase_price' : data.result[machine].drug_purchase_price,
					                        'destroy_details_quantity' : data.result[machine].destroy_details_quantity,
					                        'destroy_details_jine' : data.result[machine].drug_purchase_price*data.result[machine].destroy_details_quantity,
					                        'destroy_pici' : data.result[machine].destroy_pici				                        
					                    };
					                    $('#destructionxq-dg').datagrid('appendRow', row_data);
					                }
						     }, 				     
	                        Error: function () {  
	                            alert(Error);  
	                        }                   
	                    });    
					}

			});

			//销毁表详情
			$('#destructionxq-dg').datagrid({
				url : '',
				pagination : true,
				pageNumber : 1,
				pageSize : 10,
				singleSelect: true,
				pageList : [ 10, 20 ],
				columns : [ [ 
					{field : 'inventory_number',			title : '药品编号',		width : 148.5}, 
					{field : 'drug_name',					title : '药品名称',		width : 148.5}, 
					{field : 'drug_standard',				title : '规格',			width : 148.5}, 
					{field : 'drug_purchase_price',			title : '单价',			width : 148.5},
					{field : 'destroy_details_quantity',	title : '销毁数量',		width : 148.5},
					{field : 'destroy_details_jine',		title : '金额',			width : 148.5},
					{field : 'destroy_pici',				title : '药品批次',		width : 148.5}
				] ]
			});
			
			//销毁记录详情
			$('#destructionjl-dg').datagrid({
				url : '',
				pagination : true,
				pageNumber : 1,
				pageSize : 10,
				singleSelect: true,
				pageList : [ 10, 20 ],
				columns : [ [ 
					{field : 'inventory_number',			title : '药品编号',		width : 148.5}, 
					{field : 'drug_name',					title : '药品名称',		width : 148.5}, 
					{field : 'drug_standard',				title : '规格',			width : 148.5}, 
					{field : 'drug_purchase_price',			title : '单价',			width : 148.5},
					{field : 'destroy_details_quantity',	title : '销毁数量',		width : 148.5},
					{field : 'destroy_details_jine',		title : '金额',			width : 148.5},
					{field : 'destroy_pici',				title : '药品批次',		width : 148.5}
				] ]
			});
			
			$("#qwertya").click(function(){
				$("#destructiontbxq-win").window("close");
			});
			
			//药品销毁
			$("#destructionok").click(function(){
				//获取销毁单号
				var destroyid = $("#destruction-xhdh1").textbox("getValue");
				//获取审批人
				var checkpeople = $("#destructionpeople").val() ;	
				$.ajax({  
                    url: 'update-destroy',  
                    data:{
                    	'destroyid':destroyid,
                    	'checkpeople':checkpeople
                    },
                    type: 'POST',  
                    dataType:"json",
				 	success: function (data) {  						
						$(".drugonep").text("药品销毁成功");
				 		 //清空文本
				 		$("#DRUGONEp").window('open');
				  	 	//三秒之后自动消失
				   		setTimeout(function(){
				    	 	$("#DRUGONEp").window('close');
				    	 	$("#destructiontbxq-win").window("close");
						}, 1500);
				    }, 				     
                    Error: function () {  
                        alert(Error);  
                    }                   
                });    
				
				//获取表格中的详情记录
				var rows = $("#destructionxq-dg").datagrid("getRows");
				console.log(rows);

				var total=0;
				var money=0;
				for (var i = 0; i < rows.length; i++) {					
					//获取库存编号
					var inventorynum = rows[i]["inventory_number"];
					//获取销毁数量
					var sum =  rows[i]["destroy_details_quantity"];							
					//获取库存批次
					var batch = rows[i]["destroy_pici"];							
					$.ajax({  
	                       url: 'update-outkucun',  
	                       data:{
	                    	   'inventorynum':inventorynum,
	                    	   'sum':sum
	                       },
	                       type: 'POST',  
	                       dataType:"json",
						   success: function (data) {  
						
						   }, 				     
	                       Error: function () {  
	                           alert(Error);  
	                       }                   
	                 });    
					
					$.ajax({  
	                       url: 'update-outpici',  
	                       data:{
	                    	   'inventorynum':inventorynum,
	                    	   'sum':sum,
	                    	   'batch':batch
	                       },
	                       type: 'POST',  
	                       dataType:"json",
						   success: function (data) {  
						
						   }, 				     
	                       Error: function () {  
	                           alert(Error);  
	                       }                   
	                });     
				}
				
				//刷新表格
				$('#destructiontb-dg').datagrid('reload');
				$('#destruction-dg').datagrid('reload');
				
			});
			

		});
		
		// 时间戳
		function CurentTime(){
	  
	        var now = new Date();
	       
	        var year = now.getFullYear();       //年
	        var month = now.getMonth() + 1;     //月
	        var day = now.getDate();            //日
	       
	        var hh = now.getHours();            //时
	        var mm = now.getMinutes();          //分
			var ss = now.getSeconds();			//秒
	       
	        var clock = year + "-";
	       
	        if(month < 10)
	            clock += "0";
	       
	        clock += month + "-";
	       
	        if(day < 10)
	            clock += "0";
	           
	        clock += day + " ";
	       
	        if(hh < 10)
	            clock += "0";
	           
	        clock += hh + ":";
	        if (mm < 10) clock += '0'; 
	        clock += mm + ":"; 
			
	        if (ss < 10) clock += '0'; 
	        clock += ss; 
	        return(clock); 
		}
		
		// 时间戳
		function comFormatDate(date) {
			var day = new Date(date); 
			var Year = 0; 
			var Month = 0; 
			var Day = 0; 
			var CurrentDate = ""; 
			//初始化时间 
			Year= day.getFullYear();//ie火狐下都可以 
			Month= day.getMonth()+1; 
			Day = day.getDate(); 
			Hour = day.getHours(); 
			 Minute = day.getMinutes(); 
			 Second = day.getSeconds(); 
			CurrentDate += Year + "-"; 
			if (Month >= 10 ) { 
				CurrentDate += Month + "-"; 
			}else { 
				CurrentDate += "0" + Month + "-"; 
			} 
			if (Day >= 10 ) { 
				CurrentDate += Day ; 
			}else { 
				CurrentDate += "0" + Day ; 
			} 
			if(Hour>=10){
				CurrentDate +=" "+Hour;
			}else{
				CurrentDate +=" "+"0"+Hour;
			}
			if(Minute>=10){
				CurrentDate +=":"+Minute;
			}else{
				CurrentDate +=":"+"0"+Minute;
			}
			if(Second>=10){
				CurrentDate +=":"+Second;
			}else{
				CurrentDate +=":"+"0"+Second;
			}
			return CurrentDate; 
		}
		
	</script>

	<div id="destruction-p" class="easyui-panel" style="width: 100%; height: 100%; padding: 10px; background: #fafafa;"
		data-options="iconCls:'icon-save',closable:true,collapsible:true,minimizable:true,maximizable:true">
		
		<!-- 销毁审核 -->
		<fieldset style="border: 1px solid #A6A6A6; border-radius: 6px; width: 1050px; margin: 0 auto; margin-top: 10px; margin-bottom: 20px;">
			
			<legend style="font-size: 17px">销毁审核</legend>
			
			<table id="destructiontb-dg" class="logininform-table easyui-datagrid" style="width: 1030; height: 140px"
				data-options="toolbar:'#logininform-tb',fitColumns:false,singleSelect:false">

			</table>
		
		</fieldset>

		<fieldset style="border: 1px solid #A6A6A6; border-radius: 6px; width: 1050px; margin: 0 auto; margin-top: 10px; margin-bottom: 20px;">
			
			<legend style="font-size: 17px">销毁记录</legend>
			
			<table id="destruction-dg" class="logininform-table easyui-datagrid" style="width: 1030; height: 220px"
				data-options="toolbar:'#logininform-tb',fitColumns:false,singleSelect:false">
		
			</table>
		
		</fieldset>

	</div>

	<!-- 销毁记录详情 -->
	<div id="destructionjl-win" class="easyui-window" title="销毁详情" style="width: 1080px; height: 500px"
		data-options="iconCls:'icon-save',modal:true,closed:true,shadow:true,resizable:false,collapsible:false,minimizable:false,maximizable:false">
		
		<div class="easyui-layout" data-options="fit:true">
			
			<div data-options="region:'center'">
				
				<div style="width: 1000; height: 60px;line-height:60px; padding: 10px;margin-left: 50px;">
					
					<p>
						<span style="margin-left: 60px;"></span> 
						
						<input id="destruction-xhdh" class="easyui-textbox" style="width: 200px" data-options="label:'销毁单号：'"></input>
						
						<span style="margin-left: 60px;"></span> 
						
						<input id="destruction-yy" class="easyui-textbox" style="width: 200px" data-options="label:'原因：'"></input>
						
						<span style="margin-left: 60px;"></span> 
						
						<input id="destruction-xhsj" class="easyui-textbox" style="width: 230px" data-options="label:'销毁时间：'"></input>
						
					</p>

				</div>
				
				<div style="padding: 10px">
					
					<table id="destructionjl-dg" class="logininform-table easyui-datagrid" style="width: 1040px; height: 308px"
						data-options="toolbar:'#logininform-tb',fitColumns:false,singleSelect:false">

					</table>
				
				</div>
			
			</div>
		
		</div>
	
	</div>
	
	<!-- 销毁表详情 -->
	<div id="destructiontbxq-win" class="easyui-window" title="销毁详情" style="width: 1080px; height: 550px"
		data-options="iconCls:'icon-save',modal:true,closed:true,shadow:true,resizable:false,collapsible:false,minimizable:false,maximizable:false">
		
		<div class="easyui-layout" data-options="fit:true">
			
			<div data-options="region:'center'">
				
				<div style="width: 1000; height: 60px;line-height:60px; padding: 10px;margin-left: 50px;">
					
					<p>
					
						<span style="margin-left: 60px;"></span> 
						
						<input id="destruction-xhdh1" class="easyui-textbox" style="width: 200px" data-options="label:'销毁单号：'"></input>
												
						<span style="margin-left: 60px;"></span> 
												
						<input id="destruction-yy1" class="easyui-textbox" style="width: 200px" data-options="label:'原因：'"></input>
						
						<span style="margin-left: 60px;"></span> 
						
						<input id="destruction-xhsj1" class="easyui-textbox" style="width: 230px" data-options="label:'销毁时间：'"></input>
					
					</p>
				
				</div>
				
				<div style="padding: 10px">
					
					<table id="destructionxq-dg" class="logininform-table easyui-datagrid" style="width: 1040px; height: 308px"
						data-options="toolbar:'#logininform-tb',fitColumns:false,singleSelect:false">
			
					</table>
				
				</div>
				
				<p style="margin-left: 300px;">
					
					<a id="destructionok" style="width: 150px;" class="easyui-linkbutton" iconCls="icon-ok">确认销毁</a> 
					
					<span style="margin-left: 50px;"></span> 
					
					<a  id="qwertya" style="width: 150px;" class="easyui-linkbutton" iconCls="icon-cancel">取消</a>
				
				</p>
				
			</div>
		
		</div>
	
	</div>

	<input type="hidden" value="${user.userName}"  id="destructionpeople"> 
	
	<!-- 弹框提示 -->
	<div id="DRUGONEp" class="easyui-window"  title="提示框" style="width:300px;height:156px"
	    data-options="iconCls:'icon-save',modal:true,resizable:false,collapsible:false,maximizable:false,minimizable:false,closed:true">
	          <p class="drugonep" style="text-align:center;font-size: 16px;margin-top: 47px;">
	          </p>
	</div>

</body>
</html>